package com.shop.game.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.game.entry.Exchange;
import com.shop.game.mapper.ExchangeMapper;
import com.shop.game.service.ExchangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
@Slf4j
@Service
public class ExchangeServiceImpl implements ExchangeService {
    @Autowired
    public ExchangeMapper exchangeMapper;
    @Override
    public IPage<Exchange> selectUserAll(int pageNum, int pageSize,BigInteger userId) {
        Page<Exchange> page = new Page<>(pageNum, pageSize);
        page.addOrder(new OrderItem("price", false),new OrderItem("exchange_id", true));
        IPage<Exchange> exchanges = exchangeMapper.selectByUserId(page, userId);
        log.info("查询用户的记录:{}",userId);
        return exchanges;
    }

    @Override
    public Boolean addExchange() {
        Exchange exchange = new Exchange();
        exchange.setUserId(new BigInteger("1111")); // 设置用户ID
        exchange.setPrice(new BigDecimal("10.5")); // 设置价格
        exchange.setQuantity(10); // 设置数量
        exchange.setRemarks("测试新增"); // 设置备注
        int rows = exchangeMapper.insert(exchange);
        log.info("添加数据操作 {} 新增id:{}",rows,exchange.getExchangeId());
        return rows > 0;
    }
}
